<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			var num_ = 1;

			mui.init({
				beforeback: function() {
					//... //窗口关闭前处理其他业务详情点击 ↑ "关闭页面"链接查看
					scan.close();
				},
			});
			mui.plusReady(function() {
				//console.log("当前页面URL：" + plus.webview.currentWebview().getURL());
				startRecognize();
				scan.start();
				fl = false;
			});
			var scan = null;

			function onmarked(type, result) {
				var text = '未知: ';
				switch (type) {
					case plus.barcode.QR:
						text = 'QR: ';
						break;
					case plus.barcode.EAN13:
						text = 'EAN13: ';
						break;
					case plus.barcode.EAN8:
						text = 'EAN8: ';
						break;
					case plus.barcode.CODE128:
						text = 'CODE128: ';
						break;
				}
				var setting_ = JSON.parse(result);
				if(typeof(setting_)=='object'){
					mui.alert(setting_.token+"\n"+setting_.url, "获取参数", function() {
						plus.storage.setItem("Token",setting_.token);
						plus.storage.setItem("Url",setting_.url);
						plus.storage.setItem("downLoadStudentInfo", "{}");
						plus.storage.setItem("studentSeat", "{}");
						plus.storage.setItem("classList", "{}");
						scan.close();
						back_();
						});
				}else{
					mui.alert("error",function(){scan.start();});
					
				}
				
				



			}

			function startRecognize() {
				scan = new plus.barcode.Barcode('bcid', [plus.barcode.QR, plus.barcode.CODE128, plus.barcode.EAN13]);
				scan.onmarked = onmarked;
			}

			function startScan() {
				scan.start();
			}

			function cancelScan() {
				scan.cancel();
			}

			function setFlash() {
				if (fl != true) {
					fl = true;
				} else {
					fl = false;
				};
				scan.setFlash(fl);
			}

			function back_() {
				scan.close();
				history.back(-1);
			}

			function save_() {
				plus.storage.setItem("studentSeat", JSON.stringify(studentSeat));
				alert(JSON.stringify(studentSeat));
				back_();
			}
			/*
			window.onbeforeunload = function(event) {
				scan.close();
			}
			*/
		</script>
		<style type="text/css">
			#bcid {
				background: #FFFFFF;
				height: 360px;
				width: 100%;
				margin: 0 auto;
				text-align: center;
				vertical-align: middle;

			}
		</style>
		<header id="header" class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">获取参数</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div id="bcid"></br></br></br>数据加载中...</div>
			</div>
			<div class="mui-content-padded">
				<button type="button" class="mui-btn-primary mui-btn-block" onclick="setFlash()">灯光</button>
				<button type="button" class="mui-btn-primary mui-btn-block" onclick="back_()">返回 </button>
			</div>
			<div id='stuinfo' class="mui-card mui-row">

			</div>
		</div>
	</body>

</html>
